<!DOCTYPE html>
<html>

<head>
    <meta charset="UTF-8">
    <title>欢迎页面-X-admin2.0</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width,user-scalable=yes, minimum-scale=0.4, initial-scale=0.8,target-densitydpi=low-dpi" />
    <link rel="shortcut icon" href="/favicon.ico" type="image/x-icon" />
    <link rel="stylesheet" href="/static/css/font.css">
    <link rel="stylesheet" href="/static/css/xadmin.css">
    <script type="text/javascript" src="https://cdn.bootcss.com/jquery/3.2.1/jquery.min.js"></script>
    <script type="text/javascript" src="/static/lib/layui/layui.js" charset="utf-8"></script>
    <script type="text/javascript" src="/static/js/xadmin.js"></script>
    <!-- 让IE8/9支持媒体查询，从而兼容栅格 -->
    <!--[if lt IE 9]>
    <script src="https://cdn.staticfile.org/html5shiv/r29/html5.min.js"></script>
    <script src="https://cdn.staticfile.org/respond.js/1.4.2/respond.min.js"></script>
    <![endif]-->

    <link rel="stylesheet" href="/static/sweetalert/sweetalert.css">
    <script src="/static/sweetalert/ions_alert.js"></script>
    <script src="/static/sweetalert/sweetalert.min.js"></script>
</head>
  
  <body>
    <div class="x-body">
        <form class="layui-form">
            <div class="layui-form-item">
                <label class="layui-form-label">上级权限</label>
                <div class="layui-input-inline"  style="width: 200px;">
                    <select lay-filter="aihao" id="auth_parent_id" onchang="on_idmbzd_change()">
                        <option value="0">--无--</option>
                        {{range .auths}}
                            <option value="{{.SysId}}" >{{.AuthName}}</option>
                        {{end}}

                    </select>
                </div>
                <div class="layui-form-mid layui-word-aux">无上级权限请留空</div>
            </div>

            <div class="layui-form-item">
                <label class="layui-form-label">权限名称</label>
                <div class="layui-input-inline" style="width:200px;">
                    <input type="text" lay-verify="title" placeholder="请输入权限名称" autocomplete="off" class="layui-input" id="auth_name">
                </div>
                <div class="layui-form-mid layui-word-aux">权限名称不能重复</div>
            </div>


            <div class="layui-form-item">
                <label class="layui-form-label">URL地址</label>
                <div class="layui-input-inline" style="width:200px;">
                    <input type="text" id="auth_url" lay-verify="title" placeholder="请输入URL地址(一级菜单输入#号)" autocomplete="off" class="layui-input">
                </div>
                <div class="layui-form-mid layui-word-aux">使用urlfor规则</div>
            </div>


            <div class="layui-form-item layui-form-text">
                <label class="layui-form-label">描述</label>
                <div class="layui-input-block">
                    <textarea id="auth_desc" placeholder="请输入内容" class="layui-textarea"></textarea>
                </div>
            </div>

            <div class="layui-form-item">
                <label class="layui-form-label">是否启用</label>
                <div class="layui-input-block">
                    <input name="is_active" id="is_active_1" type="radio" value="1" checked="checked" title="启用"/>
                    <input name="is_active" id="is_active_2" type="radio" value="2" title="停用"/>
                </div>
            </div>


            <div class="layui-form-item">
                <label class="layui-form-label">权重</label>
                <div class="layui-input-inline" style="width:200px;">
                    <input type="text" id="auth_weight" lay-verify="title" placeholder="请输入数字权重" autocomplete="off" class="layui-input">
                </div>
                <div class="layui-form-mid layui-word-aux">权重只能为数字,值越大排序越前</div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">菜单图标</label>
                <div class="layui-input-inline" style="width:200px;">
                    <input type="text" id="auth_icon" lay-verify="title" placeholder="左侧菜单栏图标" autocomplete="off" class="layui-input">
                </div>
                <div class="layui-form-mid layui-word-aux">图标地址https://www.thinkcmf.com/font/font_awesome/icons.html</div>
            </div>

            <div class="layui-form-item">
                <div class="layui-input-block">
                    <div class="layui-footer" >
                        <button lay-filter="add" lay-submit class="layui-btn">立即提交</button>
                        <a href="{{urlfor "AuthController.List"}}"  class="layui-btn layui-btn-primary">返回</a>
                    </div>
                </div>
            </div>
        </form>
    </div>
    <script>

        $(function  () {
            layui.use('form', function () {
                var form = layui.form;
                //监听提交
                form.on('submit(add)', function (data) {

                    var auth_parent_id = document.getElementById("auth_parent_id").value;
                    var auth_name = document.getElementById("auth_name").value;
                    var auth_url = document.getElementById("auth_url").value;
                    var auth_desc = document.getElementById("auth_desc").value;
                    var is_active = $("input[name=is_active]:checked").val();
                    var auth_icon = document.getElementById("auth_weight").value;
                    var auth_weight = document.getElementById("auth_icon").value;
                    //获取下拉菜单选项文本框值
                    var sel_obj = document.getElementById("auth_parent_id");
                    var index = sel_obj.selectedIndex;
                    var p_name =(sel_obj.options[index].text);
                    // console.log("inside success22") ;
                    $.ajax({
                        url: "{{urlfor "AuthController.DoAdd"}}",
                        type: "POST",
                        data: {
                            "auth_parent_id": auth_parent_id,
                            "auth_name": auth_name,
                            "auth_url": auth_url,
                            "auth_desc": auth_desc,
                            "is_active": is_active,
                            "auth_weight": auth_weight,
                            "auth_icon": auth_icon,
                            "p_name": p_name

                        },
                        success: function (data) {
                            var code = data["code"];
                            // console.log(code) ;
                            if(code == 200){
                                // console.log("inside success4") ;
                                // ions_alert.alertSuccessToast(data["msg"]);
                                // setTimeout(reload_list,2000);  // 2s
                                // 获得frame索引
                                window.parent.location.reload(); //刷新父页面
                                var index = parent.layer.getFrameIndex(window.name);
                                //关闭当前frame
                                parent.layer.close(index);
                                window.location.href= "{{urlfor "AuthController.List"}}";
                                window.location.reload();
                            }else {
                                ions_alert.alertErrorToast(data["msg"]);
                                setTimeout(reload_list,2000);
                            }

                        },
                        fail: function (data) {
                            // console.log("inside fail")
                            alert(data)
                        }
                    });
                });

            });

        });

        function reload_list() {
            // console.log("inside success88") ;
            // 获得frame索引
            window.parent.location.reload(); //刷新父页面

            var index = parent.layer.getFrameIndex(window.name);

            //关闭当前frame
            parent.layer.close(index);
            window.location.href= "{{urlfor "AuthController.List"}}";
            window.location.reload();

        }

    </script>

  </body>

</html>